$(function(){
	var title = "登录提示";
	var $n = $('#username');
	var $p = $('#password');
	var $c = $('#checkCode');
	
	//当用户离开password焦点时，加密密码
	$p.blur(function(){
		if($(this).val() != '')$(this).val($.md5($(this).val()));
		//alert($(this).val());
	});
	
	//更新验证码
	$('#kaptcha').css('cursor','pointer').click(function(){
		$(this).attr('src','').attr('src','kaptcha?' + DateUtil.getCurrentDateTime('T'));
	});
	
	//收集参数
	function collectData(){
		var dataArray = new Array();
		dataArray.push('username=' + $n.val());
		dataArray.push('&password=' + $p.val());
		dataArray.push('&checkcode=' + $c.val());
		return dataArray.join('&');
	}
	
	//提交事件
	$('#submitBtn').click(function(){
		if($n.val() == ''){
			jAlert('请输入用户名',title);
			return;
		}
		if($p.val() == ''){
			jAlert('请输入密码',title);
			return;
		}
		if($c.val() == ''){
			jAlert('请输入验证码',title);
			return;
		}
		
		$.ajax({
			type:'POST',
			url:'sysLoginAction!queryLogin.ac',
			data:collectData(),
			dataType:'json',
			beforeSend:function(){
				jLoading("正在验证您的身份，请稍后...");
			},
			success:function(rs){
				if(!rs.flag){
					jAlert(rs.msg,title);
					return;
				}else{
					window.location.href = $('#basePath').val() + '/';
				}
			}
		});
	});
	
	//清空
	$('#clearBtn').click(function(){
		$n.val('');
		$p.val('');
		$c.val('');
	});
})